var a = getApp(), t = a.requirejs("core");

a.requirejs("jquery");

Page({
    data: {
        swiperCurrent: 0,
        indicatorDots: !0,
        autoplay: !0,
        interval: 3e3,
        duration: 800,
        circular: !0,
        imgUrls: [],
        links: [],
        params: {},
        lotterydraws: [],
        exchanges: [],
        coupons: [],
        balances: [],
        category: [],
        hidden: !1,
        keywords: "",
        cateshow: 0,
        page: 1,
        datas: {},
        twoclass: [],
        twostatus: 0,
        list: [],
        more: !0,
        load: !0,
        notgoods: !0,
    },
    onLoad: function(a) {
        this.setData({
            shanghuid: a.merchid
        }),
        this.get_index(), this.getList();
    },
    onShow: function() {
        var that = this;
        a.getCache("isIpx") ? that.setData({
            isIpx: !0,
            iphonexnavbar: "fui-iphonex-navbar",
            paddingb: "padding-b"
        }) : that.setData({
            isIpx: !1,
            iphonexnavbar: "",
            paddingb: ""
        })
    },
    doinput: function(a) {
        this.setData({
            keywords: a.detail.value
        });
    },
    search: function() {
        var a = "/pages/creditshop/lists/index?keywords=" + this.data.keywords + "&shanghuid=" + this.data.shanghuid;
        wx.navigateTo({
            url: a
        });
    },
    focus: function() {
        this.setData({
            showbtn: "in"
        });
    },
    // onReady: function() {
    //     this.get_index();
    // },
    changeTo: function(a) {
        var t = a.currentTarget.dataset.url + "&id=" + a.currentTarget.dataset.gid;
        wx.navigateTo({
            url: t
        });
    },
    get_index: function() {
        var a = this, params = a.data.params;
        params.shanghuid = a.data.shanghuid;
        t.post("creditshop/index", params, function(t) {
            console.log(t);
            if (0 == t.error) {
                a.setData({
                    category: t.data.category,
                    twoclass: t.data.category,
                    lotterydraws: t.data.lotterydraws,
                    exchanges: t.data.exchanges,
                    coupons: t.data.coupons,
                    balances: t.data.balances,
                    redbags: t.data.redbags,
                    sysset: t.sysset
                }), 0 !== t.data.advs.length ? a.setData({
                    imgUrls: t.data.advs,
                    shouadvs: !0
                }) : a.setData({
                    shouadvs: !1
                });
                var e = t.sysset.texts.credit + "商城首页";
                wx.setNavigationBarTitle({
                    title: e
                });
            }
            a.setData({
                hidden: !0
            });
        });
    },
    getList: function() {
        var s = this;
        s.setData({
            loading: true
        }), t.get("creditshop/lists/getlist", {
            page: s.data.page,
            keywords: "",
            shanghuid: s.data.shanghuid,
            cate: s.data.cate
        }, function(e) {
            var i = {
              loading: false,
              total: e.total,
              pagesize: e.pagesize,
              show: !0
            };
            e.list.length > 0 && (i.page = s.data.page + 1, i.list = s.data.list.concat(e.list), 
            e.list.length < e.pagesize && (i.loaded = true)), s.setData(i);
        });
    },
    twoclass: function(p) {
        var cate = Number(t.data(p).type), twostatus = Number(this.data.twostatus);
        if(cate==twostatus) return false;
        this.setData({
            list: [],
            page: 1,
            twostatus: cate,
            cate: cate,
            loaded: false,
        }), this.getList();
    },
    lower: function() {
        this.data.loaded || this.data.list.length == this.data.total || this.getList();
    },
});